﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.DAL
{
    public sealed class PurchaseOrderPenaltyDAL
    {
        IDBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);

        public PurchaseOrderPenaltyDAL()
        {

        }

        public PurchaseOrderPenaltyInfo GetPurchaseOrderPenalty(int seq)
        {
            string strSQL;
            DataSet ds;
            DataRowCollection dr;
            PurchaseOrderPenaltyInfo info = new PurchaseOrderPenaltyInfo();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT p.*"
                            + ", rt.ICM_PEN_RATE_TYPE_NAME"
                            + ", pc.ICM_PEN_COUNT_NAME"
                        + " FROM ICM_PURCHASE_ORDER_PENALTY p"
                            + " INNER JOIN ICM_SYS_PENALTY_RATE_TYPE rt ON p.ICM_PEN_RATE_TYPE_SEQ = rt.ICM_PEN_RATE_TYPE_SEQ"
                            + " INNER JOIN ICM_SYS_PENALTY_COUNT pc ON p.ICM_PEN_COUNT_SEQ = pc.ICM_PEN_COUNT_SEQ"
                        + " WHERE p.ICM_PO_PEN_SEQ = @seq";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    PurchaseOrderInfo infoPo = new PurchaseOrderInfo();
                    SysPenaltyCountInfo infoPenCount = new SysPenaltyCountInfo();
                    SysPenaltyRateTypeInfo infoPenRateType = new SysPenaltyRateTypeInfo();
                    RecordInfo infoRecord = new RecordInfo();

                    info.Seq = Convert.ToInt32(dr[0]["ICM_PO_PEN_SEQ"]);
                    infoPo.Seq = Convert.ToInt32(dr[0]["ICM_PO_SEQ"]);
                    info.Name = dr[0]["ICM_PO_PEN_NAME"].ToString();
                    info.Descr = dr[0]["ICM_PO_PEN_DESCR"].ToString();
                    info.Rate = (Convert.IsDBNull(dr[0]["ICM_PO_PEN_RATE"]) ? null : (Nullable<double>)(dr[0]["ICM_PO_PEN_RATE"]));
                    info.Least = (Convert.IsDBNull(dr[0]["ICM_PO_PEN_LEAST"]) ? null : (Nullable<double>)(dr[0]["ICM_PO_PEN_LEAST"]));
                    infoPenRateType.Seq = (Convert.IsDBNull(dr[0]["ICM_PEN_RATE_TYPE_SEQ"]) ? null : (Nullable<int>)(dr[0]["ICM_PEN_RATE_TYPE_SEQ"]));
                    infoPenRateType.Name = dr[0]["ICM_PEN_RATE_TYPE_NAME"].ToString();
                    infoPenCount.Seq = (Convert.IsDBNull(dr[0]["ICM_PEN_COUNT_SEQ"]) ? null : (Nullable<int>)(dr[0]["ICM_PEN_COUNT_SEQ"]));
                    infoPenCount.Name = dr[0]["ICM_PEN_COUNT_NAME"].ToString();

                    infoRecord.Created_by = (Convert.IsDBNull(dr[0]["CREATED_BY"]) ? null : (Nullable<int>)(dr[0]["CREATED_BY"]));
                    infoRecord.Created_when = (Convert.IsDBNull(dr[0]["CREATED_WHEN"]) ? null : (Nullable<DateTime>)(dr[0]["CREATED_WHEN"]));
                    infoRecord.Updated_by = (Convert.IsDBNull(dr[0]["UPDATED_BY"]) ? null : (Nullable<int>)(dr[0]["UPDATED_BY"]));
                    infoRecord.Updated_when = (Convert.IsDBNull(dr[0]["UPDATED_WHEN"]) ? null : (Nullable<DateTime>)(dr[0]["UPDATED_WHEN"]));

                    info.InfoPurchaseOrder = infoPo;
                    info.InfoPenaltyRateType = infoPenRateType;
                    info.InfoPenaltyCount = infoPenCount;
                    info.InfoRecord = infoRecord;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        public IList<PurchaseOrderPenaltyInfo> GetPurchaseOrderPenaltyWithParent(int PoSeq)
        {
            string strSQL;
            DataSet ds = null;
            DataRowCollection dr = null;
            IList<PurchaseOrderPenaltyInfo> infoList = new List<PurchaseOrderPenaltyInfo>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@icm_po_seq", PoSeq);

                strSQL = "select pop.icm_po_pen_seq " +
                            ", pop.icm_po_pen_name " +
                            ", pop.icm_po_pen_descr " +
                            ", pop.icm_po_pen_rate " +
                            ", pop.icm_pen_rate_type_seq " +
                            ", rt.icm_pen_rate_type_name " +
                            ", pop.icm_pen_count_seq " +
                            ", pc.icm_pen_count_name " +
                            ", pop.icm_po_pen_least " +
                            ", pop.icm_po_seq " +
                        "from icm_purchase_order_penalty pop " + 
                            "left join icm_sys_penalty_rate_type rt on pop.icm_pen_rate_type_seq = rt.icm_pen_rate_type_seq " +
                            "left join icm_sys_penalty_count pc on pop.icm_pen_count_seq = pc.icm_pen_count_seq " +
                        "where pop.icm_po_seq = @icm_po_seq";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    for (int i = 0; i < dr.Count; i++)
                    {
                        PurchaseOrderPenaltyInfo info = new PurchaseOrderPenaltyInfo();
                        SysPenaltyRateTypeInfo infoPenaltyRateType = new SysPenaltyRateTypeInfo();
                        SysPenaltyCountInfo infoPenaltyCount = new SysPenaltyCountInfo();
                        PurchaseOrderInfo infoPurchaseOrder = new PurchaseOrderInfo();

                        info.Seq = Convert.ToInt32(dr[i]["icm_po_pen_seq"]);
                        info.Name = dr[i]["icm_po_pen_name"].ToString();
                        info.Descr = dr[i]["icm_po_pen_descr"].ToString();
                        info.Rate = (Convert.IsDBNull(dr[i]["icm_po_pen_rate"]) ? null : (Nullable<double>)(dr[i]["icm_po_pen_rate"]));
                        infoPenaltyRateType.Seq = Convert.ToInt32(dr[i]["icm_pen_rate_type_seq"]);
                        infoPenaltyRateType.Name = dr[i]["icm_pen_rate_type_name"].ToString();
                        infoPenaltyCount.Seq = Convert.ToInt32(dr[i]["icm_pen_count_seq"]);
                        infoPenaltyCount.Name = dr[i]["icm_pen_count_name"].ToString();
                        info.Least = (Convert.IsDBNull(dr[i]["icm_po_pen_least"]) ? null : (Nullable<double>)(dr[i]["icm_po_pen_least"]));
                        infoPurchaseOrder.Seq = Convert.ToInt32(dr[i]["icm_po_seq"]);

                        info.InfoPenaltyRateType = infoPenaltyRateType;
                        info.InfoPenaltyCount = infoPenaltyCount;
                        info.InfoPurchaseOrder = infoPurchaseOrder;

                        info.PenaltyDetail = info.Rate.ToString() + " " + info.InfoPenaltyRateType.Name + " ต่อ " + info.InfoPenaltyCount.Name +
                            ((info.Least != null) ? "และไม่ต่ำกว่าวันละ " + ((double)info.Least).ToString("#,##0.00") + " บาท" : "");

                        infoList.Add(info);
                    }
                }
                return infoList;
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public IList<PurchaseOrderPenaltyInfo> GetPurchaseOrderPenaltyWithSearch(int po_seq, string search_text)
        {
            string strSQL;
            DataSet ds = null;
            DataRowCollection dr = null;
            IList<PurchaseOrderPenaltyInfo> infoList = new List<PurchaseOrderPenaltyInfo>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@search_text", search_text);
                dbManager.AddParameters(1, "@po_seq", po_seq);

                strSQL = "SELECT pop.ICM_PO_PEN_SEQ "
                            + ", pop.ICM_PO_PEN_NAME " 
                            + ", pop.ICM_PO_PEN_DESCR "
                            + ", pop.ICM_PO_PEN_RATE "
                            + ", pop.ICM_PEN_RATE_TYPE_SEQ "
                            + ", rt.ICM_PEN_RATE_TYPE_NAME "
                            + ", pop.ICM_PEN_COUNT_SEQ "
                            + ", pc.ICM_PEN_COUNT_NAME "
                            + ", pop.ICM_PO_PEN_LEAST "
                            + ", pop.ICM_PO_SEQ "
                        + " FROM ICM_PURCHASE_ORDER_PENALTY pop "
                            + " LEFT JOIN ICM_SYS_PENALTY_RATE_TYPE rt ON pop.ICM_PEN_RATE_TYPE_SEQ = rt.ICM_PEN_RATE_TYPE_SEQ "
                            + " LEFT JOIN ICM_SYS_PENALTY_COUNT pc ON pop.ICM_PEN_COUNT_SEQ = pc.ICM_PEN_COUNT_SEQ "
                        + " WHERE pop.ICM_PO_SEQ = @po_seq"
                            + " AND CASE WHEN @search_text = '' THEN 0 = 0"
                                + " ELSE (pop.ICM_PO_PEN_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pop.ICM_PO_PEN_RATE LIKE CONCAT('%', @search_text , '%')"
                                    + " OR rt.ICM_PEN_RATE_TYPE_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pc.ICM_PEN_COUNT_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pop.ICM_PO_PEN_LEAST LIKE CONCAT('%', @search_text , '%')"
                                + ")"
                            + " END";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    for (int i = 0; i < dr.Count; i++)
                    {
                        PurchaseOrderPenaltyInfo info = new PurchaseOrderPenaltyInfo();
                        SysPenaltyRateTypeInfo infoPenaltyRateType = new SysPenaltyRateTypeInfo();
                        SysPenaltyCountInfo infoPenaltyCount = new SysPenaltyCountInfo();
                        PurchaseOrderInfo infoPurchaseOrder = new PurchaseOrderInfo();

                        info.Seq = Convert.ToInt32(dr[i]["ICM_PO_PEN_SEQ"]);
                        info.Name = dr[i]["ICM_PO_PEN_NAME"].ToString();
                        info.Descr = dr[i]["ICM_PO_PEN_DESCR"].ToString();
                        info.Rate = (Convert.IsDBNull(dr[i]["ICM_PO_PEN_RATE"]) ? null : (Nullable<double>)(dr[i]["ICM_PO_PEN_RATE"]));
                        infoPenaltyRateType.Seq = Convert.ToInt32(dr[i]["ICM_PEN_RATE_TYPE_SEQ"]);
                        infoPenaltyRateType.Name = dr[i]["ICM_PEN_RATE_TYPE_NAME"].ToString();
                        infoPenaltyCount.Seq = Convert.ToInt32(dr[i]["ICM_PEN_COUNT_SEQ"]);
                        infoPenaltyCount.Name = dr[i]["ICM_PEN_COUNT_NAME"].ToString();
                        info.Least = (Convert.IsDBNull(dr[i]["ICM_PO_PEN_LEAST"]) ? null : (Nullable<double>)(dr[i]["ICM_PO_PEN_LEAST"]));
                        infoPurchaseOrder.Seq = Convert.ToInt32(dr[i]["ICM_PO_SEQ"]);

                        info.InfoPenaltyRateType = infoPenaltyRateType;
                        info.InfoPenaltyCount = infoPenaltyCount;
                        info.InfoPurchaseOrder = infoPurchaseOrder;

                        info.PenaltyDetail = info.Rate.ToString() + " " + info.InfoPenaltyRateType.Name + " ต่อ " + info.InfoPenaltyCount.Name +
                            ((info.Least != null) ? "และไม่ต่ำกว่าวันละ " + ((double)info.Least).ToString("#,##0.00") + " บาท" : "");

                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public IList<PurchaseOrderPenaltyInfo> GetPurchaseOrderPenaltyWithSearchFromDeliveryNote(int dn_seq, string search_text)
        {
            string strSQL;
            DataSet ds = null;
            DataRowCollection dr = null;
            IList<PurchaseOrderPenaltyInfo> infoList = new List<PurchaseOrderPenaltyInfo>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@search_text", search_text);
                dbManager.AddParameters(1, "@dn_seq", dn_seq);

                strSQL = "SELECT pop.ICM_PO_PEN_SEQ "
                            + ", pop.ICM_PO_PEN_NAME "
                            + ", pop.ICM_PO_PEN_DESCR "
                            + ", pop.ICM_PO_PEN_RATE "
                            + ", pop.ICM_PEN_RATE_TYPE_SEQ "
                            + ", rt.ICM_PEN_RATE_TYPE_NAME "
                            + ", pop.ICM_PEN_COUNT_SEQ "
                            + ", pc.ICM_PEN_COUNT_NAME "
                            + ", pop.ICM_PO_PEN_LEAST "
                            + ", pop.ICM_PO_SEQ "
                        + " FROM ICM_DELIVERY_NOTE_PENALTY dn"
                            + " INNER JOIN ICM_PURCHASE_ORDER_PENALTY pop ON dn.ICM_PO_PEN_SEQ = pop.ICM_PO_PEN_SEQ"
                            + " LEFT JOIN ICM_SYS_PENALTY_RATE_TYPE rt ON pop.ICM_PEN_RATE_TYPE_SEQ = rt.ICM_PEN_RATE_TYPE_SEQ "
                            + " LEFT JOIN ICM_SYS_PENALTY_COUNT pc ON pop.ICM_PEN_COUNT_SEQ = pc.ICM_PEN_COUNT_SEQ "
                        + " WHERE dn.ICM_DN_SEQ = @dn_seq"
                            + " AND CASE WHEN @search_text = '' THEN 0 = 0"
                                + " ELSE (pop.ICM_PO_PEN_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pop.ICM_PO_PEN_RATE LIKE CONCAT('%', @search_text , '%')"
                                    + " OR rt.ICM_PEN_RATE_TYPE_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pc.ICM_PEN_COUNT_NAME LIKE CONCAT('%', @search_text , '%')"
                                    + " OR pop.ICM_PO_PEN_LEAST LIKE CONCAT('%', @search_text , '%')"
                                + ")"
                            + " END";

                ds = dbManager.ExecuteDataSet(CommandType.Text, strSQL);
                dr = ds.Tables[0].Rows;
                if (dr.Count > 0)
                {
                    for (int i = 0; i < dr.Count; i++)
                    {
                        PurchaseOrderPenaltyInfo info = new PurchaseOrderPenaltyInfo();
                        SysPenaltyRateTypeInfo infoPenaltyRateType = new SysPenaltyRateTypeInfo();
                        SysPenaltyCountInfo infoPenaltyCount = new SysPenaltyCountInfo();
                        PurchaseOrderInfo infoPurchaseOrder = new PurchaseOrderInfo();

                        info.Seq = Convert.ToInt32(dr[i]["ICM_PO_PEN_SEQ"]);
                        info.Name = dr[i]["ICM_PO_PEN_NAME"].ToString();
                        info.Descr = dr[i]["ICM_PO_PEN_DESCR"].ToString();
                        info.Rate = (Convert.IsDBNull(dr[i]["ICM_PO_PEN_RATE"]) ? null : (Nullable<double>)(dr[i]["ICM_PO_PEN_RATE"]));
                        infoPenaltyRateType.Seq = Convert.ToInt32(dr[i]["ICM_PEN_RATE_TYPE_SEQ"]);
                        infoPenaltyRateType.Name = dr[i]["ICM_PEN_RATE_TYPE_NAME"].ToString();
                        infoPenaltyCount.Seq = Convert.ToInt32(dr[i]["ICM_PEN_COUNT_SEQ"]);
                        infoPenaltyCount.Name = dr[i]["ICM_PEN_COUNT_NAME"].ToString();
                        info.Least = (Convert.IsDBNull(dr[i]["ICM_PO_PEN_LEAST"]) ? null : (Nullable<double>)(dr[i]["ICM_PO_PEN_LEAST"]));
                        infoPurchaseOrder.Seq = Convert.ToInt32(dr[i]["ICM_PO_SEQ"]);

                        info.InfoPenaltyRateType = infoPenaltyRateType;
                        info.InfoPenaltyCount = infoPenaltyCount;
                        info.InfoPurchaseOrder = infoPurchaseOrder;

                        info.PenaltyDetail = info.Rate.ToString() + " " + info.InfoPenaltyRateType.Name + " ต่อ " + info.InfoPenaltyCount.Name +
                            ((info.Least != null) ? "และไม่ต่ำกว่าวันละ " + ((double)info.Least).ToString("#,##0.00") + " บาท" : "");

                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public void Insert(IList<PurchaseOrderPenaltyInfo> infoList, Nullable<int> po_seq, PurchaseOrderInfo info, IDBManager dbManagerTrans)
        {
            string strSQL;
            try
            {
                for (int i = 0; i < infoList.Count; i++)
                {
                    dbManagerTrans.CreateParameters(9);

                    dbManagerTrans.AddParameters(0, "@icm_po_pen_name", infoList[i].Name);
                    dbManagerTrans.AddParameters(1, "@icm_po_pen_descr", infoList[i].Descr);
                    dbManagerTrans.AddParameters(2, "@icm_po_pen_rate", infoList[i].Rate);
                    dbManagerTrans.AddParameters(3, "@icm_pen_rate_type_seq", infoList[i].InfoPenaltyRateType.Seq);
                    dbManagerTrans.AddParameters(4, "@icm_pen_count_seq", infoList[i].InfoPenaltyCount.Seq);
                    dbManagerTrans.AddParameters(5, "@icm_po_pen_least", infoList[i].Least);
                    dbManagerTrans.AddParameters(6, "@icm_po_seq", po_seq);
                    dbManagerTrans.AddParameters(7, "@created_by", info.InfoRecord.Created_by);
                    dbManagerTrans.AddParameters(8, "@created_when", info.InfoRecord.Created_when);

                    strSQL = "INSERT INTO ICM_PURCHASE_ORDER_PENALTY"
                     + " (ICM_PO_PEN_NAME, ICM_PO_PEN_DESCR, ICM_PO_PEN_RATE, ICM_PEN_RATE_TYPE_SEQ"
                     + " , ICM_PEN_COUNT_SEQ, ICM_PO_PEN_LEAST, ICM_PO_SEQ"
                     + " , CREATED_BY, CREATED_WHEN)"
                     + " VALUES (@icm_po_pen_name"
                     + ", @icm_po_pen_descr"
                     + ", @icm_po_pen_rate"
                     + ", @icm_pen_rate_type_seq"
                     + ", @icm_pen_count_seq"
                     + ", @icm_po_pen_least"
                     + ", @icm_po_seq"
                     + ", @created_by"
                     + ", @created_when"
                     + " )";

                    dbManagerTrans.ExecuteNonQuery(CommandType.Text, strSQL);
                }
            }
            catch
            {
                throw;
            }
        }

        public void Insert(PurchaseOrderPenaltyInfo info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(9);

                dbManager.AddParameters(0, "@icm_po_pen_name", info.Name);
                dbManager.AddParameters(1, "@icm_po_pen_descr", info.Descr);
                dbManager.AddParameters(2, "@icm_po_pen_rate", info.Rate);
                dbManager.AddParameters(3, "@icm_pen_rate_type_seq", info.InfoPenaltyRateType.Seq);
                dbManager.AddParameters(4, "@icm_pen_count_seq", info.InfoPenaltyCount.Seq);
                dbManager.AddParameters(5, "@icm_po_pen_least", info.Least);
                dbManager.AddParameters(6, "@icm_po_seq", info.InfoPurchaseOrder.Seq);
                dbManager.AddParameters(7, "@created_by", info.InfoRecord.Created_by);
                dbManager.AddParameters(8, "@created_when", info.InfoRecord.Created_when);

                strSQL = "INSERT INTO icm_purchase_order_penalty"
                 + " (icm_po_pen_name, icm_po_pen_descr, icm_po_pen_rate, icm_pen_rate_type_seq"
                 + " , icm_pen_count_seq, icm_po_pen_least, icm_po_seq"
                 + " , CREATED_BY, CREATED_WHEN)"
                 + " VALUES (@icm_po_pen_name"
                 + ", @icm_po_pen_descr"
                 + ", @icm_po_pen_rate"
                 + ", @icm_pen_rate_type_seq"
                 + ", @icm_pen_count_seq"
                 + ", @icm_po_pen_least"
                 + ", @icm_po_seq"
                 + ", @created_by"
                 + ", @created_when"
                 + " )";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void Update(PurchaseOrderPenaltyInfo info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(9);

                dbManager.AddParameters(0, "@icm_po_pen_seq", info.Seq);
                dbManager.AddParameters(1, "@icm_po_pen_name", info.Name);
                dbManager.AddParameters(2, "@icm_po_pen_descr", info.Descr);
                dbManager.AddParameters(3, "@icm_po_pen_rate", info.Rate);
                dbManager.AddParameters(4, "@icm_pen_rate_type_seq", info.InfoPenaltyRateType.Seq);
                dbManager.AddParameters(5, "@icm_pen_count_seq", info.InfoPenaltyCount.Seq);
                dbManager.AddParameters(6, "@icm_po_pen_least", info.Least);
                dbManager.AddParameters(7, "@updated_by", info.InfoRecord.Updated_by);
                dbManager.AddParameters(8, "@updated_when", info.InfoRecord.Updated_when);

                strSQL = "UPDATE icm_purchase_order_penalty SET "
                 + " icm_po_pen_name = @icm_po_pen_name"
                 + ", icm_po_pen_descr = @icm_po_pen_descr"
                 + ", icm_po_pen_rate = @icm_po_pen_rate"
                 + ", icm_pen_rate_type_seq = @icm_pen_rate_type_seq"
                 + ", icm_pen_count_seq = @icm_pen_count_seq"
                 + ", icm_po_pen_least = @icm_po_pen_least"
                 + ", updated_by = @updated_by"
                 + ", updated_when = @updated_when"
                 + " WHERE icm_po_pen_seq = @icm_po_pen_seq";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch
            {
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void DeleteAll(IList<PurchaseOrderPenaltyInfo> infoList)
        {
            string strSQL;
            string seq = "";
            for (int i = 0; i < infoList.Count; i++)
            {
                if (i == 0)
                {
                    seq += infoList[i].Seq;
                }
                else
                {
                    seq += "," + infoList[i].Seq;
                }
            }

            try
            {
                dbManager.Open();
                dbManager.BeginTransaction();

                strSQL = "DELETE FROM ICM_PURCHASE_ORDER_PENALTY"
                       + " WHERE ICM_PO_PEN_SEQ IN (" + seq + ")";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
                dbManager.CommitTransaction();
            }
            catch
            {
                dbManager.RollBackTransaction();
                throw;
            }
            finally
            {
                dbManager.Dispose();
            }
        }
    }
}
